var strFullPath=window.document.location.href;
var strPath=window.document.location.pathname;
var pos=strFullPath.indexOf(strPath);
var prePath=strFullPath.substring(0,pos);
var project = window.location.pathname.split("/")[1];
var url = prePath+"/"+project+"/workFile/findgoodjob.wm";
$(function () {
    initShareGoodJob();
    $("#toptitle").text("分享优秀作业");
    $("#workid").change(function () {
        getGoodJobs();
    });
});

function initShareGoodJob() {
    var data={};
    $.ajaxSetup({
        async : false
    });
    $.post(url,data,function (result) {
        var option="";
        for(var i = 0;i < result.jobtasks.length;i++){
            option+="<option value='"+result.jobtasks[i].jobTask_id+"'>"+result.jobtasks[i].jobTask_title+"</option>"
        }
        $("#workid").html(option);
        var goodworks = "";
        if(result.goodjobs.length==0){
            $("#nogoodwork").show();
            $("#goodworks").hide();
        }else{
            for(var j = 0;j < result.goodjobs.length;j++){
                goodworks += " <tr>"+
                    "<td>"+result.goodjobs[j].aStudent.student_name+"</td>"+
                    "<td></a>"+result.goodjobs[j].aStudent.student_number+"</td>"+
                    "<td>"+result.goodjobs[j].work_date+"</td>"+
                    "<td><a href='"+prePath+"/"+project+"/teacherWorkController/download.wm?workId="+result.workid+"'>"+result.goodjobs[j].work_title+"</a></td>"+
                    "<td><a href='"+prePath+"/"+project+"/workFile/stopshare.wm?jobtaskid="+result.workid+"'>取消优秀作业</a></td>"+
                    "</tr>"
            }
            $("#datas").html(goodworks);
        }

    },"json");
    // 设置分页
    $("#demo .holder").jPages({
        containerID : "datas",
        previous : "«",
        next : "»",
        perPage : 5,
        delay : 10,
        callback: function(pages, items){
            $("#total").text(items.count);
            $("#cur_page").text(pages.current);
            $("#total_page").text(pages.count);
        }
    });
}

function getGoodJobs() {
    var data = {};
    data.workid = $("#workid option:selected").val();
    $.post(url,data,function (result) {
        var goodworks = "";
        if(result.goodjobs.length==0){
            $("#nogoodwork").show();
            $("#goodworks").hide();
        }else{
            $("#nogoodwork").hide();
            $("#goodworks").show();
            for(var j = 0;j < result.goodjobs.length;j++){
                goodworks += " <tr>"+
                    "<td>"+result.goodjobs[j].aStudent.student_name+"</td>"+
                    "<td></a>"+result.goodjobs[j].aStudent.student_number+"</td>"+
                    "<td>"+result.goodjobs[j].work_date+"</td>"+
                    "<td><a href='"+prePath+"/"+project+"/teacherWorkController/download.wm?workId="+result.workid+"'>"+result.goodjobs[j].work_title+"</a></td>"+
                    "<td><a href='"+prePath+"/"+project+"/workFile/stopshare.wm?jobtaskid="+result.workid+"'>取消优秀作业</a></td>"+
                    "</tr>";
            }
            $("#datas").html(goodworks);
        }
    },"json");
}